var app = getApp();
Page({
    data: {
        luntext: ["新入", "附近", "热门"],
        activeIndex: 0,
        refresh_top: !1,
        storelist: [],
        page: 1
    },
    tabClick: function(t) {
        var e = t.currentTarget.id;
        console.log(this.data, e);
        var a = this.data.fjstorelist;
        if (0 == e);
        else if (1 == e) {
            var o = a.sort(function(t, e) {
                return (t = Number(t.distance)) < (e = Number(e.distance)) ? -1 : t > e ? 1 : 0
            });
            console.log(o), this.setData({
                store1: o
            })
        } else if (2 == e) {
            var n = a.sort(function(t, e) {
                return (t = Number(t.score)) > (e = Number(e.score)) ? -1 : t < e ? 1 : 0
            });
            console.log(n), this.setData({
                store2: n
            })
        }
        this.setData({
            activeIndex: t.currentTarget.id
        })
    },
    onLoad: function(t) {
        console.log(t), t.typename && wx.setNavigationBarTitle({
            title: t.typename
        });
        var e = this;
        wx.setNavigationBarColor({
            frontColor: "#ffffff",
            backgroundColor: wx.getStorageSync("color"),
            animation: {
                duration: 0,
                timingFunc: "easeIn"
            }
        });
        var a = wx.getStorageSync("url");
        e.setData({
            url: a,
            id: t.id
        }), e.refresh()
    },
    refresh: function(t) {
        var e = this,
            a = e.data.id,
            o = e.data.page,
            n = e.data.storelist;
        console.log(n, o), app.util.request({
            url: "entry/wxapp/TypeStoreList",
            cachetime: "0",
            data: {
                storetype_id: a,
                page: o,
                pagesize: 6
            },
            success: function(t) {
                e.setData({
                    page: o + 1
                }), console.log(t), t.data.length < 6 ? e.setData({
                    refresh_top: !0
                }) : e.setData({
                    refresh_top: !1
                });
                for (var a in t.data) {
                    var r = t.data[a].coordinates.split(",");
                    t.data[a].lat2 = Number(wx.getStorageSync("Location").latitude), t.data[a].lng2 = Number(wx.getStorageSync("Location").longitude);
                    var s = Number(wx.getStorageSync("Location").latitude),
                        i = Number(wx.getStorageSync("Location").longitude),
                        c = r[0],
                        l = r[1],
                        u = s * Math.PI / 180,
                        d = c * Math.PI / 180,
                        f = u - d,
                        g = i * Math.PI / 180 - l * Math.PI / 180,
                        h = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(f / 2), 2) + Math.cos(u) * Math.cos(d) * Math.pow(Math.sin(g / 2), 2)));
                    h *= 6378.137;
                    h = (h = Math.round(1e4 * h) / 1e4).toFixed(2);
                    t.data[a].distance = h
                }
                n = n.concat(t.data), e.setData({
                    store: n,
                    storelist: n,
                    fjstorelist: n
                })
            }
        })
    },
    store: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "../sellerinfo/sellerinfo?id=" + e,
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        })
    },
    phone: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.tel;
        wx.makePhoneCall({
            phoneNumber: e
        })
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.setData({
            activeIndex: 0,
            refresh_top: !1,
            storelist: [],
            page: 1
        }), this.refresh(), wx.stopPullDownRefresh()
    },
    onReachBottom: function() {
        console.log("上拉加载", this.data.page), 0 == this.data.refresh_top && this.refresh()
    },
    onShareAppMessage: function() {}
});